<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/9/20
 * Time: 21:43
 */

class Auth_model extends CI_Model
{
    function ver_cookie($cookie)
    {
        $sql = /** @lang text */
            "SELECT id,expire,powerId FROM ws_user WHERE token='$cookie'";
        $query = $this->db->query($sql);
        $expire = time();
        //判断用户存在
        if ($query->row() && 1800 > ($expire - $query->result_array()[0]['expire'])) {
            $powerId = $query->result_array()[0]['powerId'];
            //cookie未过期
            return json_encode(array('result' => SUCCESS, 'msg' => '欢迎登录文思学堂！', 'p' => $powerId));
        } else {
            return json_encode(array('result' => ERROR, 'msg' => '登录超时！请重新登录！', 'p' => 0));
        }
    }
}